// This file is part of OpenTSDB.
// Copyright (C) 2015  The OpenTSDB Authors.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version.  This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.  You should have received a copy
// of the GNU Lesser General Public License along with this program.  If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.tsd.http;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import net.opentsdb.query.pojo.Validatable;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = Result.Builder.class)
public class Result<T> extends Validatable {
    private int code;
    private String message;
    private T data;

    public Result(Builder builder) {
        code = builder.code;
        message = builder.message;
        data = (T) builder.data;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    /** @return A new builder for the downsampler */
    public static Builder Builder() {
        return new Builder();
    }

    /**
     * A builder
     */
    @JsonIgnoreProperties(ignoreUnknown = true)
    @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
    public static final class Builder<T> {
        @JsonProperty
        private int code;
        @JsonProperty
        private String message;
        @JsonProperty
        private T data;

        public void setCode(int code) {
            this.code = code;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public void setData(T data) {
            this.data = data;
        }

        public Result build() {
            return new Result(this);
        }
    }

    @Override
    public void validate() {
    }

}
